var vm = new Vue({
    //vue对象节点,指向父盒子
    el:'#viewTopic',                                                            
    //vue实例 的data属性
    data:function(){
        return{
          //帖子详情
  	      topic:{},
  	      topicV:false,
  	      topicData:{
  	    	  "user":{},
  	    	  "plate":{},
  	    	  "topic":{}
  	      },
  	      id:'',
  	      flag:true,
  	      rcontent:'',
  	      commentList:[{'rcontent':'hahhaha','r_create_time':'2018:02:23 11:23:40'}]
        }
    },
    //vue实例 的methods
    methods:{
    	getRecord(lid){
     	   var url = "./selectLetterByPrimary.action";
     	   var params = {
     		   'letter.lid':lid
     	   }
     	   pb.ajaxPost(url,params,function(r){
 	       		if(r.code == '000000'){
 	       			vm.topicData = r.letter;
 	       			vm.topicData.l_create_time = moment(vm.topicData.l_create_time).format('YYYY-MM-DD HH:mm:ss'); 	       			 	       			
 	       			
 	       			$('#content').append(r.letter.lcontent);
 	       		
 	       		}else{
 	       		 pb.alertErr('获取信息失败');
 	       		}
 	       },function(err){
 	    	   pb.alertErr('获取信息失败');
 	       });
        },
        open(){
      	   window.parent.vm.goTo('viewTopic',vm.topicData.topic.tid);
         },
        addReply:function(){
        	if(vm.rcontent == null || vm.rcontent== ''){
        		pb.alertWar('评论不能为空');
        		return;
        	}
        	var url = './saveReply.action';
            var params = {
          		"reply.rcontent":vm.rcontent,
          		"reply.topic.tid":vm.id
            };
            
            pb.ajaxPost(url,params,function(r){
            	if(r.code == '000000'){
                    vm.getReplys();
            	}else{
            		pb.alertErr("发表失败");
            	}
            	},function(err){
            		pb.alertErr("操作超时");
            	});
        },
        addZan(){
        	++vm.topicData.zan;
        	var url = './addZan.action';
            var params = {
          		"letter.lid":vm.id,
          		"letter.zan":vm.topicData.zan
            };
            
            pb.ajaxPost(url,params,function(r){
            	if(r.code == '000000'){
                    vm.getReplys();
            	}else{
            		pb.alertErr("发表失败");
            	}
            	},function(err){
            		pb.alertErr("操作超时");
            });
        },
        getReplys:function(){
        	 var params = {
           		"pagemap.tid":vm.id,
           		"pagemap.page":1,
           		"pagemap.size":100,
             };
        	pb.ajaxPost("./listReplyByPage.action",params,function(r){
            	if(r.code == '000000'){
            		vm.rcontent = '';
            		vm.commentList = r.replys;
            		vm.commentList.forEach(function(item){
            			item.r_create_time = momnet(item.r_create_time).format('YYYY-MM-DD');
            		});
            	}else{
            		pb.alertErr("加载评论失败");
            	}
        	},function(err){
        		pb.alertErr("操作超时");
        	});
        },
        loadData:function(){
        	$('#content').empty();
        	vm.id = pb.getQueryString('id');
        	vm.getRecord(vm.id);
        }
    }
    //vue实例 的methods结束
});
vm.loadData();